package cn.quevo.cube.provide.define.validate.impl;

import cn.quevo.common.lang.EnumUtils;
import cn.quevo.common.lang.StringUtils;
import cn.quevo.cube.provide.define.entity.dto.CubeColumnDto;
import cn.quevo.cube.provide.define.enums.DateFormat;
import cn.quevo.cube.provide.define.validate.AbstractColumnTypeValidate;
import cn.quevo.cube.provide.define.validate.ColumnTypeValidate;
import cn.quevo.cube.provide.define.validate.tools.ColumnExtTool;
import cn.quevo.cube.provide.exception.SequenceException;
import cn.quevo.cube.provide.exception.response.ColumnExceptionResponse;

/**
 * 日期验证
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2018/12/14 4:57 PM
 * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
 */
public class DateValidate extends AbstractColumnTypeValidate implements ColumnTypeValidate {
    @Override
    protected void checked(CubeColumnDto cubeColumnDto) {
        String formatter = super.getCustomParam("formatter");
        if (StringUtils.isBlank(formatter) || !EnumUtils.existsEnumIgnoreCase(formatter, DateFormat.values())) {
            throw new SequenceException(ColumnExceptionResponse.DATE_FORMATER_FAILD);
        }
        cubeColumnDto.setMinLength(null);
        cubeColumnDto.setMinLength(null);
        cubeColumnDto.setMaxValue(null);
        cubeColumnDto.setMinValue(null);
        cubeColumnDto.setDecimalNum(null);
        ColumnExtTool.initCubeColumnExt(cubeColumnDto, "日期格式", "formatter", formatter);
    }
}
